package IO;

import java.io.*;
import java.util.Scanner;

public class WriterFile {
    // 通过创建writer实例,会自动创建出这个路径名的文件
    public static void main(String[] args) {
        try (Writer writer = new FileWriter("d:/test.txt")) {
            writer.write("哈哈哈");
            writer.write("666");
            //刷新缓冲区(buffer)
            writer.flush();
        }catch (IOException e) {
            e.printStackTrace();
        }
        try (InputStream inputStream = new FileInputStream("d:/test.txt")) {
            //scanner 里面的System.in其实是一个输入流对象 InputStream
            //scanner的close本质上是对 输入流对象的关闭 而当try()执行完后,inputstream 自动关闭了,那么scanner其实也就不必要close了
            Scanner scanner = new Scanner(inputStream);
            //此时读取的文件将从文件读取
            scanner.next();
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
